
#include <algorithm>
#include <gtest\gtest.h>
#include "AutoTrace.h"

namespace inline_demo {

	int m, n;

	int pow(int n) {
		return n * n;
	}

	inline int pow_inline_version(int n) {
		return n * n;
	}

	TEST(Inline, test_diff_of_inline)
	{
		const int loops = 10000000;
		{
			AutoTrace autoTrace("pow");
			for(int i = 0; i < loops; i ++) {
				m = pow(i);
			}
		}
		std::cout << m << std::endl;
		{
			AutoTrace autoTrace("pow_inline_version");
			for(int i = 0; i < loops; i ++) {
				n = pow_inline_version(i);
			}
		}
		std::cout << n << std::endl;
	}


	enum TrigFuns {SIN, COS, TAN};

#define IL

	IL float calc_trig (TrigFuns fun, float val)
	{
		switch (fun) {
		case SIN: return sin(val);
		case COS: return cos(val);
		case TAN: return tan(val);
		}
	}

	IL TrigFuns get_trig_fun()
	{
		return SIN; 
	}

	IL float get_float()
	{
		return 90;
	}

	float calculator()
	{
		TrigFuns tf = get_trig_fun();
		float value = get_float();
		return calc_trig(tf, value);
	}

	TEST(Inline, cross_call_optimization)
	{
		const int loops = 10000000;
		{
			AutoTrace autoTrace("calculator");
			for(int i = 0; i < loops; i ++) {
				m = calculator();
			}
		}
		std::cout << m << std::endl;
	}
}